(function() {
  //// 1. 实例化对象
  //var myChart = echarts.init(document.querySelector(".map .chart"));
  //// 2. 指定配置和数据
    var myChart = echarts.init(document.querySelector(".map .chart"));
    var option = {
        tooltip: {
            formatter:function(params,ticket, callback){
                return params.seriesName+'<br />'+params.name+'：'+params.value
            }//数据格式化
        },
        visualMap: {
            min: 0,
            max: 1500,
            left: 'left',
            top: 'bottom',
            text: ['高','低'],//取值范围的文字
            inRange: {
                color: ['#e0ffff', '#006edd']//取值范围的颜色
            },
            show:true//图注
        },
        geo: {
            map: 'china',
            roam: false,//不开启缩放和平移
            zoom:1.23,//视角缩放比例
            label: {
                normal: {
                    show: true,
                    fontSize:'10',
                    color: 'rgba(0,0,0,0.7)'
                }
            },
            itemStyle: {
                normal:{
                    borderColor: 'rgba(0, 0, 0, 0.2)'
                },
                emphasis:{
                    areaColor: '#F3B329',//鼠标选择区域颜色
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        },
        series : [
            {
                name: '信息量',
                type: 'map',
                geoIndex: 0,
                data:[]
            }
        ]
    };
    var t2 = null;
    t2 = setTimeout(total2, 1000); //開始运行
    var dataList = [];
    function total2() {
        clearTimeout(t2); //清除定时器
        $.ajax({
            type: "post",
            async: false,
            url: "../connect/Map_selection_information.php",
            data: {},
            dataType: "json",
            success: function (result) {
                if (result) {
                    dataList=[];
                    for(var i=0;i<result.length;i++){
                        dataList.push({'name':result[i].name,'value':result[i].value});
                    }
                }
            },
            error: function(errmsg) {
                alert("Ajax获取服务器数据出错了！"+ JSON.stringify(errmsg));
            }
        })
        option.series[0].data = dataList;
        //alert(data);
        myChart.setOption(option);
        window.addEventListener("resize", function() {
            myChart.resize();
        });
        t2 = setTimeout(total2, 1000); //设定定时器，循环运行
        //    return num1,num2;
    }
    myChart.on('click', function (params) {
        alert(params.name);
    });
})();
